<?php
require("smarty/Smarty.class.php");
require_once("config.class.php");

class !!!projectname!!!_Smarty extends Smarty {

				private $project_name = null;
				private $current= __FILE__;

				function __construct(){
								parent::__construct();
								$this->project_name = Config::getProjectName();
								$dir = $this->get_project_root();
								$this->template_dir = "$dir".DIRECTORY_SEPARATOR."views".DIRECTORY_SEPARATOR;
								$this->compile_dir = $dir.DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."smarty".DIRECTORY_SEPARATOR."templates_c".DIRECTORY_SEPARATOR;
								$this->config_dir = $dir.DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."smarty".DIRECTORY_SEPARATOR."configs".DIRECTORY_SEPARATOR;
								$this->cache_dir = $dir.DIRECTORY_SEPARATOR."libs".DIRECTORY_SEPARATOR."smarty".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
								$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
				}

	private function get_project_root(){

					$dir = dirname($this->current);
					$dirs = array();
					if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
						$dirs = split("\\\\", $dir);
					} else {
						$dirs = split(DIRECTORY_SEPARATOR, $dir);
					}
					if(in_array($this->project_name, $dirs)){
									$index = array_search($this->project_name, $dirs);
									$new_dirs = array();

									for($i=0; $i<=$index; $i++){
													$new_dirs[] = $dirs[$i];
									}

									return implode(DIRECTORY_SEPARATOR, $new_dirs);
					}else {

									return "../";
					}

	}

}


?>
